package com.jd.sunny.java;

import java.util.ArrayList;

/**
 * @Description:Test ArrayList
 * @author:sunlin
 * @since:2012-11-28 11:22
 * @version:1.0.0
 */
public class TestArrayList {

    public static void main(String[] args) {
        testArrayList();
    }


    /**
     * test ArrayList
     */
    public static void testArrayList(){
        Cat cat1 = new Cat();
        Cat cat2 = new Cat();
        cat1.setName("mao");
        cat1.setSex("man");
        cat2.setName("mimi");
        cat2.setSex("woman");
        ArrayList<Cat> catArrayList = new ArrayList<Cat>();
        catArrayList.add(cat1);
        catArrayList.add(cat2);
        System.out.println("catArrayList size = " + catArrayList.size());

        //get ArrayList element
        Cat cat3  =  catArrayList.get(0);
        System.out.println("get ArrayList element:" +  cat3.toString());

        //user foreach to get ArrayList element
        for(Cat cat:catArrayList){
            System.out.println("use foreach:" + cat.toString());
        }

        //use toArray method to transform ArrayList into array
        Cat[] cats = new Cat[catArrayList.size()];
        catArrayList.toArray(cats);
        System.out.println("cat[0] : " + cats[0]);

        //here must use Integer ,can't use int
        ArrayList<Integer> numberArrayList = new ArrayList<Integer>();

    }

}

